//  Copyright (c) Microsoft Corporation.  All Rights Reserved.

namespace EAI.Common
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography.X509Certificates;

    public class Utils
    {
        public static X509Certificate2 GetCertificate(StoreName name, StoreLocation location, X509FindType findType, object value)
        {
            X509Store store = new X509Store(name, location);
            try
            {
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2 cert = store.Certificates.Find(findType, value, false)[0];
                store.Close();
                return cert;
            }
            catch (Exception ex)
            {
                store.Close();
                Console.WriteLine("Unable to extract Certificate: {0}", ex.ToString());
                throw;
            }
        }
    }
}
